package com.fecean.aabbc.commons.validator;


import java.util.Map;

/**
 * @author Zhengjingfeng
 * @created 2019/4/28 9:11
 * @comment
 */
public class ValidationResult {

    /**
     * 校验结果是否有错
     */
    private boolean hasErrors;

    /**
     * 校验错误信息
     */
    private Map<String, String> errorMsg;

    /**
     * return the {@link ValidationResult#hasErrors}
     */
    public boolean isHasErrors() {
        return hasErrors;
    }

    /**
     * @param hasErrors the {@link ValidationResult#hasErrors} to set
     */
    public void setHasErrors(boolean hasErrors) {
        this.hasErrors = hasErrors;
    }

    /**
     * return the {@link ValidationResult#errorMsg}
     */
    public Map<String, String> getErrorMsg() {
        return errorMsg;
    }

    /**
     * @param errorMsg the {@link ValidationResult#errorMsg} to set
     */
    public void setErrorMsg(Map<String, String> errorMsg) {
        this.errorMsg = errorMsg;
    }

    public String getFirstErrorMsg() {
        return errorMsg == null ? null : errorMsg.values().stream().findFirst().orElse(null);
    }

    public String getAllErrorMsg() {
        return errorMsg == null ? null : errorMsg.values().toString();
    }

    @Override
    public String toString() {
        return "ValidationResult [hasErrors=" + hasErrors + ", errorMsg=" + errorMsg + "]";
    }
}
